<template>
  <div>
    <TableList
      :records="ShowList"
      @docOpen="docOpen"
      @changeValue="changeValueFn"
    />
    <Detail v-show="isAll" :single="single" @docClose="isAll = false" />
  </div>
</template>

<script>
import TableList from '@/components/TableList.vue'
import Detail from '@/components/Detail.vue'

export default {
  components: { TableList, Detail },
  data() {
    return {
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        },
      ],
      isName: '',
      single: {},
      isAll: false,
    }
  },
  computed: {
    ShowList() {
      if (!this.isName) {
        return this.records
      } else {
        return this.records.filter((item) => item.doctor === this.isName)
      }
    },
  },
  methods: {
    docOpen(item) {
      this.single = item
      this.isAll = true
    },
    //
    changeValueFn(unameValue) {
      // console.log('changeValueFn', unameValue)
      if (unameValue) {
        this.isName = unameValue
      } else {
        this.isName = ''
      }
    },
  },
}
</script>

<style></style>
